package com.sita.bike.ui.activity.roadtrust;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.PopupWindow;

import com.sita.bike.R;

/**
 * Created by hongyun on 2016/1/13.
 */
public class SharePopupWindow extends PopupWindow {

    private ImageView imgViewShare, imgViewTrack;
    private View mBackgroundView;

    public SharePopupWindow(Activity context, final OnClickListener itemsOnClick) {
        super(context);
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mBackgroundView = inflater.inflate(R.layout.road_trust_share_popup, null);
        imgViewShare = (ImageView) mBackgroundView.findViewById(R.id.iv_share);
        imgViewTrack = (ImageView) mBackgroundView.findViewById(R.id.iv_track);

        //设置按钮监听
        imgViewTrack.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                itemsOnClick.onClick(v);
                dismiss();
            }
        });
        imgViewShare.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                itemsOnClick.onClick(v);
                dismiss();
            }
        });
        //设置SelectPicPopupWindow的View
        this.setContentView(mBackgroundView);
        //设置SelectPicPopupWindow弹出窗体的宽
        this.setWidth(LayoutParams.MATCH_PARENT);
        //设置SelectPicPopupWindow弹出窗体的高
        this.setHeight(LayoutParams.WRAP_CONTENT);
        //设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        //设置SelectPicPopupWindow弹出窗体动画效果
        this.setAnimationStyle(R.style.AnimBottom);
        //实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(0xb0000000);
        //设置SelectPicPopupWindow弹出窗体的背景
        this.setBackgroundDrawable(dw);
        //mMenuView添加OnTouchListener监听判断获取触屏位置如果在选择框外面则销毁弹出框
        mBackgroundView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
//        mBackgroundView.setOnTouchListener(new OnTouchListener() {
//
//            public boolean onTouch(View v, MotionEvent event) {
//
//                int height = mBackgroundView.findViewById(R.id.pop_layout).getTop();
//                int y = (int) event.getY();
//                if (event.getAction() == MotionEvent.ACTION_UP) {
//                    if (y < height) {
//                        dismiss();
//                    }
//                }
//                return true;
//            }
//        });

    }

}
